<template>
	<view class="container">
		<nv :config="config"></nv>
		<image src="../static/img/hyzx-bj@2x.png" style="width: 750rpx;height: 424rpx;position: fixed;left: 0;top: 0;"></image>
		<view class="user-info flex f-align f-justifyB">
			<view class="flex f-align">
				<view class="avatar-box f-center">
					<image :src="userInfo.userHeadPortrait" style="width: 100rpx;height: 100rpx;"></image>
				</view>
				<view class="flex f-column f-justifyC ml20" style="height: 140rpx;">
					<text class="font32 white" style="width: 300rpx;">{{userInfo.userName}}</text>
					<text class="font28 white mt10">{{userInfo.userPhone}}</text>
				</view>
			</view>
			<view class="flex f-column f-align bold" style="color: #6C5333;">
				<text class="font36">当前次卡</text>
				<text class="font60 mt20">{{userInfo.setUpNumber}}张</text>
			</view>
		</view>
		<text class="font32 gray333 font-box">次卡套餐</text>
		<view class="flex f-column f-align vip-box">
			<view @click="selectHandle(item)" v-for="(item,index) in dataList" :key="index" :class="{'active': setUpId == item.id}" class="item-box f-center f-column" style="color: #6C5333;">
				<text class="font30">{{item.washShoesNumber}} 次卡</text>
				<view class="flex f-align-end mt10">
					<text class="font32" style="line-height: 70rpx;">￥</text>
					<text class="font60 bold">{{item.taocanMoney}}</text>
				</view>
				<text class="font30 mt10">{{item.title}}</text>
				<!-- <text class="font30 mt10">{{item.taocanMoney}}元任意洗{{item.washShoesNumber}}件衣</text> -->
			</view>
		</view>
		<view class="detail-bottom flex f-align f-justifyB">
			<view class="flex f-align-end" style="color: #6C5333;">
				<text class="font32" style="line-height: 70rpx;">￥</text>
				<text class="font60 bold">{{totalMoney}}</text>
			</view>
			<view class="btn-box f-center" @click="buyHandle">立即购买</view>
		</view>
	</view>
</template>

<script>
	import nv from "@/components/pyh-nv/pyh-nv.vue";
	import { mapState, mapMutations } from 'vuex'
	export default {
		data() {
			return {
				config: {
					title: '我的VIP',
					// bgColor: 'rgba(0,0,0,0)',
					color: '#ffffff',
					hideback: false
				},
				dataList: [],
				setUpId: '',
				totalMoney: 0
			}
		},
		computed: {
			...mapState(['userInfo'])
		},
		components: {
			nv
		},
		onLoad() {
			this.getDataList()
		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			...mapMutations(['login']),
			getUserInfo() {
				this.$http.ajax({
					url: '/User/wxSelect',
					params: {
						openId: uni.getStorageSync('openId')
					}
				}).then((res) => {
					if (res.code == 0) {
						uni.setStorageSync('userInfo', res.data[0])
						this.login(res.data[0])
					}
				})
			},
			buyHandle() {
				if (!this.setUpId) {
					this.$api.msg('请选择次卡套餐')
					return
				}
				
				uni.showLoading({
					title: '请求中，请稍后...',
					mask: true
				})
				
				let _this = this
				this.$http.ajax({
					url: '/pay/unifiedSetUp',
					params: {
						openId: uni.getStorageSync('openId'),
						setUpId: this.setUpId
					}
				}).then((res) => {
					uni.hideLoading()
					if (res.code == 200) {
						uni.requestPayment({
							provider: 'wxpay',
						
							timeStamp: res.data.timeStamp,
							nonceStr: res.data.nonceStr,
							package: res.data.package,
							signType: 'MD5',
							paySign: res.data.paySign,
						
							success: (e) => {
								_this.$api.msg('支付成功')
							},
							fail: (e) => {
								_this.$api.msg('支付失败')
							}
						})
					} else {
						this.$api.msg(res.msg)
					}
				})
			},
			selectHandle(item) {
				this.setUpId = item.id
				this.totalMoney = item.taocanMoney
			},
			getDataList() {
				this.$http.ajax({
					url: '/SetUp/list',
					params: {},
				}).then((res) => {
					if (res.code == 200) {
						this.dataList = res.data
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		padding: 0;
		
		.font-box {
			position: fixed;
			top: 466rpx;
			left: 0;
			z-index: 99;
			padding-top: 50rpx;
			background-color: #F5F5F5;
			width: 100%;
			padding-left: 40rpx;
			padding-bottom: 10rpx;
		}
		
		.detail-bottom {
			width: 686rpx;
			height: 150rpx;
			padding-left: 32rpx;
			padding-right: 32rpx;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
			position: fixed;
			right: 0;
			bottom: 0;
			background: #FFFFFF;
			box-sizing: content-box;
		
			.btn-box {
				width: 280rpx;
				height: 100rpx;
				background: linear-gradient(90deg, #FCEBCF 0%, #EED4A2 100%);
				border-radius: 56rpx;
				font-size: 46rpx;
				line-height: 64rpx;
				color: #6C5333;
			}
		}

		.vip-box {
			padding: 374rpx 32rpx 260rpx;

			.item-box {
				width: 560rpx;
				height: 240rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 8rpx 12rpx rgba(154, 101, 37, 0.64);
				border-radius: 12rpx;
				margin: 50rpx 40rpx 0;
			}

			.active {
				background: linear-gradient(360deg, #F2D6A3 0%, #FDE9CC 100%);
			}
		}

		.user-info {
			width: 686rpx;
			height: 260rpx;
			background-image: url();
			background-size: 100% 100%;
			box-shadow: 0rpx 8rpx 12rpx rgba(154, 101, 37, 0.64);
			border-radius: 12rpx;
			position: fixed;
			top: 206rpx;
			left: 32rpx;
			z-index: 99;
			padding-left: 46rpx;
			padding-right: 68rpx;

			.avatar-box {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				overflow: hidden;
			}
		}

		::v-deep .nvBox {
			background: rgba(0, 0, 0, 0) !important;
		}
	}
</style>
